using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Scorm_Content_Editor
{
    public partial class NewCourse : Form
    {
        public int gambar = 1; //field untuk dikirim ke luar sebagai parameter gambar yang dipilih

        public NewCourse()
        {
            InitializeComponent();
            
        }
        
        //kode berikut merupakan event handler yang terdapat dalam dialog ini
                
        private void Button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog browseFolder = new FolderBrowserDialog() ;

            if (browseFolder.ShowDialog() == DialogResult.OK)
            {
                txtLocation.Text = browseFolder.SelectedPath.ToString();
            }
            else 
            { 
                txtLocation.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 
            }
        }
               
        private void txtName_TextChanged(object sender, EventArgs e)
        {
            if (File.Exists(txtLocation.Text + "\\" + txtName.Text + ".rse"))
            {
                MessageBox.Show("File Already Exist!");
            }
                this.wizard1.NextEnabled = this.txtName.Text.Length > 0 &&
                                           !File.Exists(txtLocation.Text + "\\" + txtName.Text + ".rse") && 
                                           !Directory.Exists(txtLocation.Text + "\\" + txtFolderName.Text) &&
                                           this.txtFolderName.Text.Length > 0 &&
                                           this.txtLocation.Text.Length > 0;
           
        }

        private void txtFolderName_TextChanged(object sender, EventArgs e)
        {
            if (Directory.Exists(txtLocation.Text + "\\" + txtFolderName.Text))
            {
                MessageBox.Show("Directory Already Exist at this Location!");
            }
            this.wizard1.NextEnabled = this.txtName.Text.Length > 0 &&
                                       !File.Exists(txtLocation.Text + "\\" + txtName.Text + ".rse") &&
                                       !Directory.Exists(txtLocation.Text + "\\" + txtFolderName.Text) &&
                                       this.txtFolderName.Text.Length > 0 &&
                                       this.txtLocation.Text.Length > 0;
        }
                
        private void txtLocation_TextChanged(object sender, EventArgs e)
        {
            if (File.Exists(txtLocation.Text + "\\" + txtName.Text + ".rse"))
            {
                MessageBox.Show("File Already Exist!");
            }
                this.wizard1.NextEnabled = this.txtName.Text.Length > 0 &&
                                           !File.Exists(txtLocation.Text + "\\" + txtName.Text + ".rse") &&
                                           !Directory.Exists(txtLocation.Text + "\\" + txtFolderName.Text) &&
                                           this.txtFolderName.Text.Length > 0 &&
                                           this.txtLocation.Text.Length > 0;       
        }
     

        private void wizard1_AfterSwitchPages(object sender, CristiPotlog.Controls.Wizard.AfterSwitchPagesEventArgs e)
        {
            CristiPotlog.Controls.WizardPage  newPage = this.wizard1.Pages[e.NewIndex];
            
            if (newPage == this.wizardPage2)
            {               
               this.wizard1.NextEnabled = this.txtName.Text.Length > 0 &&
                                          !File.Exists(txtLocation.Text + "\\" + txtName.Text + ".rse") &&
                                          !Directory.Exists(txtLocation.Text + "\\" + txtFolderName.Text) &&
                                       this.txtFolderName.Text.Length > 0 &&
                                          this.txtLocation.Text.Length > 0;    
            }
            if (newPage == this.wizardPage1)
            {
                this.wizard1.NextEnabled = this.txtModuleName.Text.Length > 0;                              
            }  
        }

        private void txtModuleName_TextChanged(object sender, EventArgs e)
        {
            this.wizard1.NextEnabled = this.txtModuleName.Text.Length > 0;
        }


       

      
    }
}